Exercise 1: Connecting an Azure Web Role to an External SQL Server Database with Windows Azure Connect

In this exercise, you will setup network connectivity between a simple Web Role and your local machine. The Web Site used for sample purposes in this exercise will leverage Windows Azure Connect and connect to your local SQL Server instance to retreive a list of customers that will be shown in a simple table within the site.


Task 1 - Configuring the Application to run in Windows Azure with Windows Azure Connect

To use Windows Azure Connect to connect external resources with your Azure service, you need to enable one or more of its roles.You do this by provisioning the role with the Connect plug-in that is part of the Windows Azure SDK v1.5 release. Only roles of the service provisioned with the Connect plug-in will be able to connect to external resources.

  1. In order to make the Azure Web Role be able to connect with the database using SQL Server credentials, open SQL Server Management Studio and connect to the local SQL Server (i.e. .\sqlexpress).
  2. Right click in the server node and select Properties.
  3. Select Security and make sure SQL Server and Windows Authentication mode is selected.

    Figure 1
    SQL Server Properties - Security


  4. Click OK button.
  5. Restart the SQL Server instance in order to make previous configuration change to take effect.

    Figure 2
    Restart SQL Server


  6. Execute the CreateDatabase.cmd script located in the \Source\Setup\Scripts folder.
    Note:
    In order to continue the exercise make sure you executed the setup.cmd as mentioned in the Setup section of this lab.


  7. Open Visual Studio 2010 as an administrator. Go to File | Open | Project menu and select the Begin.sln located in \Source\Ex1-ConnectingToExternalSQL\Begin folder of the lab.
  8. Press F5 key to run the application.
  9. Notice in the connection information panel that the application is connected to the local SQL Server SQLEXPRESS instance.

    Figure 3
    Application running locally


  10. Navigate to http://windows.azure.com.
  11. Click Virtual Network link on Windows Azure Platform left pane. This are the contents related to Windows Azure Connect.

    Figure 4
    Clicking Virtual Network


  12. Click {your-service-subscription-name} node located under Connect node on the upper side of left pane.
  13. Click Ok on Enable Windows Azure Connect popup. This popup appears only the first time you need to enable Windows Azure Connect with the current subscription.

    Figure 5
    Enabling Windows Azure Connect


  14. Once enabled, click Close on Enable Windows Azure Connect popup.

    Figure 6
    Windows Azure Connect enabled


  15. Click {your-service-subscription-name} node to expand and see Windows Azure Connect information. To do this, click Connect node on the upper side of the left pane.

    Figure 7
    Reviewing Windows Azure Connect information


  16. Click the “Get Activation Token” button. You will retrieve the “client activation token” for your Windows Azure service.

    Figure 8
    Getting Activation Token


  17. Click Copy Token to Clipboard button on Get Activation Token for Windows Azure Roles popup to configure your Windows Azure Service.

    Figure 9
    Copying Client Activation token


  18. Click Yes if Microsoft Silverlight ask you to allow clipboard access.

    Figure 10
    Allowing Silverlight access clipboard


  19. Click Ok to close the Get Activation Token for Windows Azure Roles popup.

    Figure 11
    Closing popup


  20. Go back to Visual Studio 2010. Under the CustomerSearch project, open the CustomersWebRole settings and select the VirtualNetwork tab. Ensure that the option labeled Activate Windows Azure Connect is selected. Paste from the clipboard the token you have copied in the previous step.

    Figure 12
    Filling Virtual Network tab


  21. Press Ctrl-S to save config file.
  22. Open the Web.config file for the CustomersWebRole project to update the SQL connection string. Find the CustomersEntitiesconnectionString, and replace the .\SQLEXPRESS value in the Data Source attribute to {your-machine-name}\SQLEXPRESS,1433. The number 1433 in the attribute represents the port number. The following snippet show the result after applying the update, assuming that your machine name is “YourMachine” (replace this value with your machine mane):
    Note:
    To retrieve your computer’s name by going to Start, right-click on Computer and select Properties. The computer name will be displayed in the middle of the Properties window.


  23. XML Copy Code
      <connectionStrings>
        ...
    
    <add name="CustomersEntities" connectionString="metadata=res://*/Customers.csdl|res://*/Customers.ssdl|res://*/Customers.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=YourMachine\SQLEXPRESS,1433;Initial Catalog=Customers;Persist Security Info=True;User ID=labUser;Password=Passw0rd!;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    
      </connectionStrings>
    

    Note:
    Once you deploy the application to Windows Azure, the Web Role will connect to the SQL Server running in your machine through the machine name. That is the reason why you need to change the .\SQLExpress value to use explicitly your machine name. Notice also that you need to explicitly specify the default port as part of the data source because the connection will be set using TCP/IP as the protocol.


  24. You need to deploy the solution to Windows Azure. You can deploy the application using the Windows Azure Tools for Visual Studio, or create a service package and use the portal to deploy it. For more information on deployment options, see the “Windows Azure Deployment” hands-on lab.
  25. Once the deployment completed successfully you should see information about the roles in Virtual Network. To do this, click Connect node on the left pane.

    Figure 13
    Roles information


  26. Click Hosted Services, Storage Account CDN link on the left pane to review your role information. If Hosted Services is not already selected, click Hosted Services to select it.

    Figure 14
    Selecting Compute, Storage & CDN


  27. Click your service located on the center pane to review your service information. Once selected, click the DNS Name link on the right pane. This opens the published Web site.

    Figure 15
    Clicking on Web Site URL


  28. Verify that the application is running in Windows Azure, without being able to connect to the external SQL server machine. You should see an exception saying that the connection to SQL Server could not be established.

    Figure 16
    Application running in Azure, showing an exception saying that the connection to SQL Server could not be established


Task 2 - Installing Windows Azure Connect Endpoint Software in Your External Machine to Enable Windows Azure Connect

  1. Click back on Virtual Network.
  2. Click the Install Local Endpoint button.

    Figure 17
    Getting Install link


  3. Click Copy Linkto Clipboard button on the Install Windows Azure Connect Endpoint Software popup.

    Figure 18
    Client Installation Link


  4. Click Yes if Microsoft Silverlight ask you to allow clipboard access.

    Figure 19
    Allowing Silverlight access clipboard


  5. Click Ok to close the popup.
  6. Paste the copied link in the Internet Explorer navigation bar and press enter to download the client.
  7. Click Run button to install the Windows Azure Connect Endpoint software.

    Figure 20
    Downloading the Windows Azure Connect Endpoint software


  8. Click Run button in the Security Warning dialog.
  9. Click Yes button if the UAC dialog appears.
  10. Follow the steps in the Windows Azure Connect Endpoint software installation wizard.

    Figure 21
    Windows Azure Connect Endpoint software installation wizard


  11. To verify that the Windows Azure Connect Endpoint software installed successfully, right click the icon in the tray.

    Figure 22
    Windows Azure Connect Endpoint software icon


  12. Click Open Windows Azure Connect.

    Figure 23
    Windows Azure Connect Endpoint software context menu


  13. The Windows Azure Connect dialog box will show the current status.

    Figure 24
    Windows Azure Connect status


    Note:
    In case you cannot get Windows Azure Connect endpoint configured check the Windows Service “IKE and AuthIP IPsec Keying Modules” is running.


  14. We are able to create groups. To do this, go back to browser. Click Virtual Network on left pane.
  15. Once the Windows Azure Connect Endpoint software is running locally, our external machine is shown in the center pane. To review this, click Groups and Roles node on the left pane.

    Figure 25
    Windows Azure Connect, your external machine added


Task 3 - Configuring Microsoft SQL Server Express for Remote Access

Microsoft SQL Server Express needs to be accessible from the machines in our local network. If your SQL Server Express instance is already enabled for remote access, you will notice that many of the instructions below are not necessary, in either case, we recommend you go through the steps below to confirm.

  1. To enable remote connections, Open SQL Server Management Studio and connect to the local SQL Server.
  2. Right click in the server node and select Properties.
  3. Select Connections and make sure Allow remote connections to this server option is checked.

    Figure 26
    Server Properties - Connections


  4. Open SQL Server Configuration Manager.
  5. Make sure the SQL Server Browser service is disabled or stopped.

    Figure 27
    SQL Server Browser stopped


  6. Enable TCP/IP Protocol in the SQL Server Network Configuration / Protocols for SQLEXPRESS.

    Figure 28
    Enabling TCP/IP protocol


  7. Edit TCP/IPprotocolProperties. Select the IP Addresses tab. Scroll to the bottom of the form until you locate the IP All entry, and make sure the TCP Dynamic Ports is set to blank. Then set the TCP Port to 1433.

    Figure 29
    TCP/IP Protocol properties


    Note:
    The SQL Browser service is only required when using dynamic ports for remote connections, in our scenario, we simply want to expose the default TCP port: 1433. The benefit of having this service running is that users connecting remotely do not have to specify the port in the connection string, but on the other hand, it is a security best practice to not run the SQL Browser service as it reduces the attack surface area by eliminating the need to listen on a UDP port.


  8. Click OK.
  9. Restart the SQL Service. To do this right click SQL Server and click Restart.

    Figure 30
    SQL Server service running


  10. To allow TCP connections to go throw the firewall we need to add a new rule. Open Windows Firewall with Advanced Security.
  11. Select Inbound Rules. Create a New Rule.

    Figure 31
    Windows Firewall – Inbound Rules – New Rule


  12. In the New Inbound Rule Wizard select Port for the rule type.

    Figure 32
    New Inbound Rule Wizard – Rule Type step


  13. Set the TCP port to 1433.

    Figure 33
    New Inbound Rule Wizard – Protocols and Ports step


  14. Select Allow the Connection in the Action step.

    Figure 34
    New Inbound Rule Wizard – Action step


  15. Apply the rule to all the profiles in the Profile step.

    Figure 35
    New Inbound Rule Wizard – Profile step


  16. Set the name to SQLPort in the Name step and click Finish.

    Figure 36
    New Inbound Rule Wizard – Name step


Task 4 - Managing Windows Azure Connect Groups

To allow access between the external machines and the Windows Azure Roles a group linking the Azure Roles and the external machines should be created. The following steps are the instructions to do this.

  1. Go back to the browser. Click Virtual Network link on left pane.
  2. Click Create Group button.

    Figure 37
    Creating a Group


  3. In the Create a New Endpoint Group popup add a GroupName, a Description, and optionally check Allow connections between endpoints in group to enable connectivity between external machines of the group.

    Figure 38
    Filling Create a New Endpoint Group popup


  4. Click Add button on Connect from.

    Figure 39
    Adding local endpoints


  5. Select your local endpoint from the available endpoints.

    Figure 40
    Adding local endpoints


  6. Click Ok button.
  7. Click Add button on Connect to.

    Figure 41
    Adding Azure roles


  8. Select your roles from the available groups and roles.

    Figure 42
    Adding Azure roles


  9. Click Ok button to close popup.
  10. Click Create button in order to create a new endpoint group.

    Figure 43
    Creating a new endpoint group


  11. Your new group is now set. Make sure the new group policies were updated in the external machine. To do this, right click the Windows Azure Connect endpoint software Refresh Policy the tray.

    Figure 44
    Refreshing local policies


  12. Once the policies are updated, Open Windows Azure Connect and verify you are in an endpoint group.

    Figure 45
    Local status


Verification

At this point, you should have network connectivity between the Azure Role and your local machine. Let’s run the application again and verify this by repeating the steps used in task 1.

  1. Click Hosted Services, Storage Account & CDN link on the left pane to review your role information.

    Figure 46
    Selecting Compute, Storage & CDN


  2. Click your service located on the center pane to review your service information. Once selected, click the DNS Name link to navigate to the Web role.

    Figure 47
    Clicking on Web Site URL


  3. We can verify that our application is running in Windows Azure, and retrieving the date from the external SQL server machine.

    Figure 48
    Application running in Azure with Windows Azure Connect


    Note:
    Take into account that the endpoint may take several minutes to be added to the new group. You will get “the underlying provider failed to open” errors until the endpoint is ready.